<meta charset="UTF-8">
<?php
require ('./lib/init.php');

//查询所有栏目
$sql = "select cat_name,cat_id from cat";
$cats = mGetAll($sql);


//判断地址栏是否有cat_id
 if (isset($_GET['cat_id'])){
     $where = " and art.cat_id = $_GET[cat_id]" ;
 }else{
     $where = "";
 }

//分页代码
$sql = "select count(*) from art where 1 " . $where;//总文章数量
$num = mGetOne($sql);//总文章
$curr = isset($_GET['page']) ? $_GET['page'] : 1;//当前页码
$cnt = 4 ;//每页显示条数
$page = getPage($num,$curr,$cnt);


//查询所有的文章
$sql = "select art.art_id,author,title,content,pubtime,comm,cat_name,thumb from art inner join cat on 
    art.cat_id = cat.cat_id where 1 " . $where . ' order by art_id desc limit ' . ($curr-1) * $cnt . ',' . $cnt;
 $arts = mGetAll($sql);

// 当前栏目无文章 跳转到首页
if (empty($arts)){
    header('location:index.php');
}
require(ROOT . '/view/front/index.html');

?>